#!coding=utf-8
from weixin.signals import wxsignal_subscribe_event, wxsignal_unsubscribe_event,\
    wxsignal_click_event, wxsignal_view_event, wxsignal_location_event,\
    wxsignal_scan_event, wxsignal_location_select_event, wxsignal_location
from weixin.send.msg import data_to_xml

def process_subscribe_event(msg):
    data = wxsignal_subscribe_event.send(sender='weixin',msg=msg)
#     print data
    if len(data) >= 1:
        for i in range(0,len(data)):
            if data[i][1]!=None:
                return data_to_xml(msg,data[i][1])
        return 'null'
    else:
        return 'null'


def process_unsubscribe_event(msg):
    data = wxsignal_unsubscribe_event.send(sender='weixin',msg=msg)
    if len(data) >= 1:
        for i in range(0,len(data)):
            if data[i][1]!=None:
                return data_to_xml(msg,data[i][1])
        return 'null'
    else:
        return 'null'


def process_click_event(msg):
    data = wxsignal_click_event.send(sender='weixin',msg=msg)
    if len(data) >= 1:
        for i in range(0,len(data)):
            if data[i][1]!=None:
                return data_to_xml(msg,data[i][1])
        return 'null'
    else:
        return 'null'


def process_view_event(msg):
    data = wxsignal_view_event.send(sender='weixin',msg=msg)
    if len(data) >= 1:
        for i in range(0,len(data)):
            if data[i][1]!=None:
                return data_to_xml(msg,data[i][1])
        return 'null'
    else:
        return 'null'


def process_location_event(msg):
    data = wxsignal_location_event.send(sender='weixin',msg=msg)
    if len(data) >= 1:
        for i in range(0,len(data)):
            if data[i][1]!=None:
                return data_to_xml(msg,data[i][1])
        return 'null'
    else:
        return 'null'

def process_location_msg(msg):
    data = wxsignal_location.send(sender='weixin',msg=msg)
    if len(data) >= 1:
        for i in range(0,len(data)):
            if data[i][1]!=None:
                return data_to_xml(msg,data[i][1])
        return 'null'
    else:
        return 'null'


def process_scan_event(msg):
    data = wxsignal_scan_event.send(sender='weixin',msg=msg)
    if len(data) >= 1:
        for i in range(0,len(data)):
            if data[i][1]!=None:
                return data_to_xml(msg,data[i][1])
        return 'null'
    else:
        return 'null'

def process_location_select_event(msg):
    data = wxsignal_location_select_event.send(sender='weixin',msg=msg)
    if len(data) >= 1:
        for i in range(0,len(data)):
            if data[i][1]!=None:
                return data_to_xml(msg,data[i][1])
        return 'null'
    else:
        return 'null'
    
    
    
    